<?php
if (file_exists("php/config.json"))
    header("Location: /");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MicroBoard | 留言板</title>

    <script src="library/jquery-3.6.0.js"></script>
    <script src="library/bootstrap3/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="library/bootstrap3/css/bootstrap.min.css">
    <link rel="stylesheet" href="library/font-awesome-4.7.0/css/font-awesome.min.css">
</head>
<body>
    <div class="container col-md-8 offset-md-2">
        <h1 class="row">安装</h1>
        <form>
            <div class="row">
                <label>
                    数据库地址
                    <input class="form-control" value="localhost" name="host">
                </label>
            </div>
            <div class="row">
                <label>
                    用户名
                    <input class="form-control" value="root" name="username">
                </label>
            </div>
            <div class="row">
                <label>
                    密码
                    <input class="form-control" value="" name="password">
                </label>
            </div>
            <div class="row">
                <label>
                    端口号
                    <input class="form-control" value="3306" name="port">
                </label>
            </div>
            <div class="row">
                <label>
                    数据库名
                    <input class="form-control" value="microBoard" name="database">
                </label>
            </div>
            <div class="row">
                <button id="submit" class="btn btn-primary" type="button">
                    安装
                </button>
            </div>
        </form>

        <div class="row">
            作者：2019计算机科学与技术3班吴博维 <br> 指导老师: 李康顺教授 <br>
            作品完成于 2021-6-10
        </div>
    </div>

    <script>
        $("#submit").click(function(){
            $.ajax({
                type: "POST",
                data: $("form").serialize(),
                url: "php/Install.php",
                dataType: "json",
                error: function(){

                },
                complete: function (xhr) {
                    if (xhr.responseText === "1") {
                        alert("安装成功");
                        window.location.replace("/");
                    }
                    else {
                        alert(xhr.responseText)
                    }
                }

            })
        });


    </script>
</body>
</html>